using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Pheonix.Fashionzoomer.BLL;
using System.Collections.Generic;
using Pheonix.CodeLibrary.Web;

public partial class page_private_admin_staticcontent : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SessionManager.LoggedUser = new CurrentUser();

        Title = SiteName + " - Static Content [ Admin ]";

        // First time bind the drop down list and for auto post back
        if (!IsPostBack)
            BindDropDownLists();
    }

    /// <summary>
    /// Loads the static content [ html only ] by the selected content id
    /// </summary>
    /// <param name="contentId">id of the content</param>
    private void LoadContent(int contentId)
    {
        // If perticular content is selected, then sets the FCKEditor with the loaded content, otherwise clears it
        if (contentId > 0)
            contentEditor.Value = StaticContentManager.GetStaticContent((StaticContentType)contentId);
        else
            contentEditor.Value = String.Empty;
    }

    /// <summary>
    /// Binds Content Drop down list
    /// </summary>
    private void BindDropDownLists()
    {
        // Getting data to generate drop down list
        List<StaticContentType> dataList = StaticContentManager.GetAllContentTypes();

        // Populating drop down list with collected data
        for (int i = 0; i < dataList.Count; i++)
        {
            contentIdList.Items.Add(new ListItem(dataList[i].ToString(), ((int)dataList[i]).ToString()));
        }
    }

    protected void save_Click(object sender, ImageClickEventArgs e)
    {
        int contentId = 0;

        // If successfuly collected the content id from drop down list
        if (Int32.TryParse(contentIdList.SelectedValue, out contentId))
        {
            // update the new content
            StaticContentManager.UpdateStaticContent((StaticContentType)contentId, contentEditor.Value);
        }
    }

    protected void contentIdList_Changed(object sender, EventArgs e)
    {
        LoadContent(Int32.Parse(contentIdList.SelectedValue));
    }
}
